package com.kingdee.pda.entity;

import com.kingdee.pda.ui.goods_putaway.OwnerBean;

import java.security.acl.Owner;
import java.util.ArrayList;
import java.util.List;

/**
 * 仓库库位
 * Created by zhanlg
 * DATE 2021/5/26
 * TIME 16:02
 */
public class WarehouseLocation {
    //仓库ID
    private long warehouseId;
    //仓库编码
    private String warehouseNum;
    //仓库名称
    private String warehouseName;
    //库位ID
    private long id;
    //库位ID
    private long locationId;
    private String locationCode;
    private String locationName;
    private int baseqty;
    private int avbbaseqty;
    private int preinbaseqty;
    //库容上限
    private int locationLimit;
    //库区编码
    private String areaNumber;
    //库区名称
    private String areaName;
    //库区类型
    private int areaType;
    //库位占用数
    private int reservoeQty;
    //    //库位库存数
//    private int stockQty;
//    //库位可用数(可移出数量)
//    private int availableQty;
//    //库位待移入数
//    private int waitMoveQty;
    private int allWaitMoveQty;
    //上架顺序
    private int launchSort;
    //商品ID
    private long skuId;
    //商品编码
    private String skuCode;
    //商品名称
    private String skuName;
    //是否移出
    private boolean isMoveOut;
    //剩余数量
    private int remainQuantity;
    //补货推荐顺序
    private int replenishSort;
    private String ownerName;//货主名称
    private String ownerNumber;//货主编码

    private long invStatusId;//库存状态id
    private String invStatusName;//库存状态
    private List<LocationListBean> list;
    private LocationListBean selectedStatusBean = null;//选中的库存状态
    private OwnerBean selectedOwnerBean = null;//选中的货主


    /**
     * 计算该库位的可移入数量
     *
     * @return
     */
    public int getCanMoveInQty() {
        int allStockQty = 0;
        int allWaitQty = 0;
        for (LocationListBean listBean : getList()) {
            allStockQty += listBean.getStockQty();
            allWaitQty += listBean.getWaitMoveQty();
        }
        //可移入量 = 库位的库容 - 库位库存数 - 该库位待移入数量
        int canMoveInQty = getLocationLimit() - allStockQty - allWaitQty;
        return canMoveInQty;
    }

    /**
     * 计算该库位的可移出数量
     *
     * @return
     * @locationListBean 选中的库存状态
     */
    public int getCanMoveOutQty() {
        if (selectedStatusBean == null) return 0;
        for (LocationListBean listBean : getList()) {
            if (selectedStatusBean.getInvStatusId() == listBean.getInvStatusId()) {
                return listBean.getAvailableQty();
            }
        }
        return 0;
    }

    /**
     * 计算该库位的可移出数量
     *
     * @return
     * @locationListBean 选中的库存状态
     */
    public int getCanMoveOutQtyWithOwner() {
        if (selectedOwnerBean == null) return 0;
        for (LocationListBean listBean : getList()) {
            if (selectedOwnerBean.getOwner() == listBean.getOwner()) {
                return listBean.getAvailableQty();
            }
        }
        return 0;
    }

    /**
     * 所有库存状态的库位库存数之和
     *
     * @return
     */
    public int getAllStockQty() {
        int qty = 0;
        for (LocationListBean bean : getList()) {
            qty += bean.getStockQty();
        }
        return qty;
    }

    /**
     * 所有库存状态的库位可用数之和
     *
     * @return
     */
    public int getAllAvailableQty() {
        int qty = 0;
        for (LocationListBean bean : getList()) {
            qty += bean.getAvailableQty();
        }
        return qty;
    }

    /**
     * 所有库存状态的库位待移入数之和
     *
     * @return
     */
    public int getAllWaitMoveQty() {
        int qty = 0;
        for (LocationListBean bean : getList()) {
            qty += bean.getWaitMoveQty();
        }
        return qty;
    }

    public void setAllWaitMoveQty(int allWaitMoveQty) {
        this.allWaitMoveQty = allWaitMoveQty;
    }

    public LocationListBean getSelectedStatusBean() {
        return selectedStatusBean == null ? new LocationListBean() : selectedStatusBean;
    }

    public void setSelectedStatusBean(LocationListBean selectedStatusBean) {
        this.selectedStatusBean = selectedStatusBean;
    }

    public OwnerBean getSelectedOwnerBean() {
        return selectedOwnerBean == null ? new OwnerBean() : selectedOwnerBean;
    }

    public void setSelectedOwnerBean(OwnerBean selectedOwnerBean) {
        this.selectedOwnerBean = selectedOwnerBean;
    }

    public void setOwnerNumber(String ownerNumber) {
        this.ownerNumber = ownerNumber;
    }

    public List<LocationListBean> getList() {
        if (list == null) {
            return new ArrayList<>();
        }
        return list;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public void setList(List<LocationListBean> list) {
        this.list = list;
    }

    public long getInvStatusId() {
        return invStatusId;
    }

    public void setInvStatusId(long invStatusId) {
        this.invStatusId = invStatusId;
    }

    public String getInvStatusName() {
        return invStatusName == null ? "" : invStatusName;
    }

    public void setInvStatusName(String invStatusName) {
        this.invStatusName = invStatusName;
    }

    public String getOwnerNumber() {
        return ownerNumber == null ? "" : ownerNumber;
    }

    public String getOwnerName() {
        return ownerName == null ? "" : ownerName;
    }

    public void setOwnerName(String ownerName) {
        this.ownerName = ownerName;
    }

    public int getRemainQuantity() {
        return remainQuantity;
    }

    public int getReplenishSort() {
        return replenishSort;
    }

    public void setReplenishSort(int replenishSort) {
        this.replenishSort = replenishSort;
    }

    public void setRemainQuantity(int remainQuantity) {
        this.remainQuantity = remainQuantity;
    }

    public long getWarehouseId() {
        return warehouseId;
    }

    public void setWarehouseId(long warehouseId) {
        this.warehouseId = warehouseId;
    }

    public String getWarehouseNum() {
        return warehouseNum;
    }

    public void setWarehouseNum(String warehouseNum) {
        this.warehouseNum = warehouseNum;
    }

    public String getWarehouseName() {
        return warehouseName;
    }

    public void setWarehouseName(String warehouseName) {
        this.warehouseName = warehouseName;
    }

    public long getLocationId() {
        return locationId;
    }

    public void setLocationId(long locationId) {
        this.locationId = locationId;
    }

    public String getLocationCode() {
        return locationCode;
    }

    public void setLocationCode(String locationCode) {
        this.locationCode = locationCode;
    }

    public String getLocationName() {
        return locationName;
    }

    public void setLocationName(String locationName) {
        this.locationName = locationName;
    }

    public int getLocationLimit() {
        return locationLimit == 0 ? Integer.MAX_VALUE : locationLimit;
    }

    public void setLocationLimit(int locationLimit) {
        this.locationLimit = locationLimit;
    }

    public String getAreaNumber() {
        return areaNumber;
    }

    public void setAreaNumber(String areaNumber) {
        this.areaNumber = areaNumber;
    }

    public String getAreaName() {
        return areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }

    public int getAreaType() {
        return areaType;
    }

    public void setAreaType(int areaType) {
        this.areaType = areaType;
    }

    public int getReservoeQty() {
        return reservoeQty;
    }

    public void setReservoeQty(int reservoeQty) {
        this.reservoeQty = reservoeQty;
    }

    public int getLaunchSort() {
        return launchSort;
    }

    public void setLaunchSort(int launchSort) {
        this.launchSort = launchSort;
    }

    public long getSkuId() {
        return skuId;
    }

    public void setSkuId(long skuId) {
        this.skuId = skuId;
    }

    public String getSkuCode() {
        return skuCode;
    }

    public void setSkuCode(String skuCode) {
        this.skuCode = skuCode;
    }

    public String getSkuName() {
        return skuName;
    }

    public void setSkuName(String skuName) {
        this.skuName = skuName;
    }

    public boolean isMoveOut() {
        return isMoveOut;
    }

    public void setMoveOut(boolean moveOut) {
        isMoveOut = moveOut;
    }

    public int getBaseqty() {
        return baseqty;
    }

    public void setBaseqty(int baseqty) {
        this.baseqty = baseqty;
    }

    public int getAvbbaseqty() {
        return avbbaseqty;
    }

    public void setAvbbaseqty(int avbbaseqty) {
        this.avbbaseqty = avbbaseqty;
    }

    public int getPreinbaseqty() {
        return preinbaseqty;
    }

    public void setPreinbaseqty(int preinbaseqty) {
        this.preinbaseqty = preinbaseqty;
    }

    public String getAreaTypeName(int areaType) {
        switch (areaType) {
            case 1:
                return "收货区";
            case 2:
                return "拣货区";
            case 3:
                return "备货区";
            case 4:
                return "退货区";
            case 5:
                return "次品区";
            case 6:
                return "分拣区";
            case 7:
                return "待上架区";
        }
        return "";
    }
}
